import { ajax, tools } from './ajax.js';

//#region 邮箱找回密码
let txt_username = document.getElementById('txt_username');
let txt_code = document.getElementById('txt_code');
let btnSend = document.getElementById('btnSend');
let txt_password = document.getElementById('txt_password');
let btnOk = document.getElementById('btnOk');

btnSend.addEventListener('click', () => {
  ajax.post(
    '/tool/sendUserEmailCode',
    {
      username: txt_username.value,
    },
    (data) => {
      showToast(data.message);
    }
  );
});

btnOk.addEventListener('click', () => {
  ajax.post(
    '/user/auth/findPwdByEmail',
    {
      username: txt_username.value,
      code: txt_code.value,
      password: tools.md5(txt_password.value),
    },
    (data) => {
      showToast(data.message);
    }
  );
});

//#endregion

//#region 弹出层提示框
let liveToast = document.getElementById('liveToast');
const toast = new bootstrap.Toast(liveToast);

const toastBody = document.querySelector('#liveToast .toast-body');

function showToast(message) {
  toastBody.innerHTML = message;
  toast.show();
}
//#endregion
